import BasePresenter from "../../../../../../redare/presenter/BasePresenter";
import * as CommonHttp from "../../../http/component/common/CommonHttp";

/**
 * Created by RdevPlugins.JsPresenterBuilderAction on 2020-03-07 13:02:40.
 */

export default class CommonPresenter extends BasePresenter {

    /**
     * @param body: {parentMenuId,sortToTree}
     * @returns Promise
     */
    findUserMenu(body, success, fails) {

        if (this._onBeforeFindUserMenu) {
            let data = this._onBeforeFindUserMenu(body);
            if (!data || typeof data !== 'object') {
                return;
            }
            body = data.body;
        }

        CommonHttp.findUserMenu(body).then(
            result => {
                this.closeDoingIndicator();
                this.closeLoadingIndicator();
                this.closeLoadMoreIndicator();

                if (success) {
                    success(result);
                    return;
                }

                if (this._onBeforeFindUserMenuSuccess) {
                    result = this._onBeforeFindUserMenuSuccess(result, {body});
                }

                if (this.view && this.view._onFindUserMenuSuccess) {
                    this.view._onFindUserMenuSuccess(result, {body});
                }
            },
            error => {
                this.closeDoingIndicator();
                this.closeLoadingIndicator();
                this.closeLoadMoreIndicator();
                this.tipError(error);

                if (fails) {
                    fails(error);
                }
            }
        );
    }

}
